package com.naruto.thinkmgr.web;

import com.naruto.thinkmgr.bean.Page;
import com.naruto.thinkmgr.bean.PageParm;
import com.naruto.thinkmgr.bean.User;
import com.naruto.thinkmgr.service.UserService;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/user")
@Slf4j//lombok自动生成log对象
public class UserController {

//    private log log = logFactory.getlog(UserController.class);

    //    @Reference(version = "1.0.0", check = false)
//    @InterfaceMethods(methods = {@Method(name = "addUser", retries = 0, timeout = 3000)})
    @Autowired
    private UserService userService;

    @GetMapping("")
    public String list(PageParm pageParm, User user, Model model) {
        this.log.debug("获取用户列表");
        Page<User> pageUser = this.userService.queryUserByPage(pageParm, user);
        model.addAttribute("page", pageUser);
        return "user/list.html";
    }


    @ResponseBody
    @GetMapping("/queryUserPage")
    public Page<User> queryUserPage() {
        log.info("consumer call queryUserPage");
        return userService.queryUserPage();
    }

    @GetMapping("/addUser")
    public String addUser() {
        log.info("consumer call addUser");
        userService.addUser(new User());
        return "index";
    }

    @GetMapping("/getUserByName")
    @ResponseBody
    public User getUserByName(String userName) {
        User user = userService.getUserByName(userName);
        return user;
    }
}
